<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var arr = [65, 45, 98, 23, 18, 66, 86]

    //第一次
    for (var i = 1; i < arr.length; i++) {
        if (arr[0] > arr[i]) {
            var min = arr[0];
            arr[0] = arr[i];
            arr[i] = min;
        }
    }
    document.write(arr + "<br>")

    //第二次
    for (var i = 2; i < arr.length; i++) {
        if (arr[1] > arr[i]) {
            var min = arr[1];
            arr[1] = arr[i];
            arr[i] = min;
        }
    }
    document.write(arr + "<br>")

    //合起来
    for (var j = 0; j < arr.length; j++) {
        for (var i = j + 1; i < arr.length; i++) {
            if (arr[j] > arr[i]) {
                var min = arr[j];
                arr[j] = arr[i];
                arr[i] = min;
            }
        }
    }
    document.write(arr + "<br>")
</script>

</html>